package com.nancy.java_design.prototype.demo2;


import java.io.*;

public class Client {
    // 原型模式，深克隆
    public static void main(String[] args) throws Exception {
        Certificate certificate1 = new Certificate();
        Student student = new Student();
        student.setName("张三");
        certificate1.setStudent(student);

        //为了防止浅克隆出现的问题，需要使用深克隆，将对象通过序列化和反序列化实现深克隆
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\certificate.txt"));
        oos.writeObject(certificate1);

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:\\certificate.txt"));
        Certificate certificate2 = (Certificate) ois.readObject();
        Student student2 = new Student();
        student2.setName("李四");
        certificate2.setStudent(student2);

        certificate1.display();
        certificate2.display();


    }
}
